package kara;

import java.util.Scanner;

public class A105P2 {
    static int n;
    static int k;
    static int[] h;
    static int[] e;
    static int[] ne;
    static int idx=1;
    static int[] vis;
    static int count=0;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        k=sc.nextInt();
        h=new int[n+1];
        vis=new int[n+1];
        e=new int[k+10];
        ne=new int[k+10];
        for(int i=1;i<=k;i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            add(a, b);
        }
        dfs(1);
        if(count==n)System.out.println(1);
        else System.out.println(-1);
    }
    static void add(int x,int y){
        e[idx]=y;
        ne[idx]=h[x];
        h[x]=idx++;
    }
    //
    static void dfs(int cur){
        if(vis[cur]==1){
            //如果该节点被访问过
            return;
        }
        vis[cur]=1;
        count++;
        for(int edge=h[cur];edge!=0;edge=ne[edge]){
            int end=e[edge];
                dfs(end);
        }
    }

}